package com.cn.hty.controller;

import com.alibaba.fastjson.JSON;
import com.cn.hty.pojo.User;
import com.cn.hty.service.IUserService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController
{

  @Resource
  private IUserService userService;

  @RequestMapping("/showUser")
  public String toIndex(HttpServletRequest request, Model model)
  {
    int userId = Integer.parseInt(request.getParameter("id"));

    User user = new User();
    user.setId(Long.valueOf(userId));
    user.setName("hutingyu");
    model.addAttribute("user", user);
    return "showUser";
  }

  @RequestMapping("/getbook")
  public String getbook(HttpServletRequest request, Model model)
  {
    String json = "{'data':[{'id':'2','name':'数学','author':'hty','price':'100'},{'id':'2','name':'英语','author':'hty','price':'1000'}]}";
    return JSON.toJSONString(json);
  }
}